import Pool from './base/pool'
let instance

export default class DataBus {
    constructor() {
        if(instance) return instance
        instance = this

        this.pool = new Pool()

        this.winW = window.innerWidth
        this.winH = window.innerHeight
        this.gridConfig = {
            top: this.winH*.35,
            height: this.winH*.65,
            row: 4,
            column: 4
        }
        this.gridConfig.unitW = this.winW / this.gridConfig.row
        this.gridConfig.unitH = this.gridConfig.height / this.gridConfig.column - 5

        this.reset()
    }

    reset() {
        this.frequency = 100
        this.frame = 0
        this.score = 0
        this.grid = {}
        this.people = []
        this.animations = []
        this.gameOver = false
    }

    removePerson(person) {
        const i = this.people.findIndex(p => p.pos === person.pos)
        this.people.splice(i, 1)
        person.visible = false
        this.pool.recover('person', person)
        this.grid[person.pos].occupied = false

        // console.log(`people destroyed at pos:${person.pos}`)
    }
}